package com.example.controller;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.model.User;
import com.example.service.UserService;

@RestController
public class TestController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 一般post请求 
	 * http://localhost:8080/hello?userId=1
	 */
	@RequestMapping("/hello")
	public String testHello(String userId,String name) {
		System.out.println("userId="+userId);
		System.out.println("name="+name);
		return "hello spring boot";
	}
	
	/**
	 * restful风格请求
	 * http://localhost:8080/add/1/ccc
	 */
	@RequestMapping(value = {"/add/{id}/{name}"},method=RequestMethod.GET)
	public String add(@PathVariable("id") int userId,@PathVariable("name") String name) {
		System.out.println("id="+userId);
		System.out.println("name="+name);
		return "hello:"+userId;
	}
	/**
	 * 测试mybaties集成情况
	 */
	@RequestMapping("/getUser")
	public List<User> getUser() {
		List<User> list = userService.getAllUser();
		System.out.println("list:"+list);
		return userService.getAllUser();
	}


}
